package com.woniuxy.customer;

import com.rabbitmq.client.Channel;
import com.woniuxy.service.AiService;
import com.woniuxy.util.ConstantUtil;
import com.woniuxy.util.ResponseUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class MsgCustomer implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnCallback{
    @Resource
    private AiService aiService;
    @RabbitListener(queues = ConstantUtil.AI_QUEUE)
    public String receiveMsg(String msg, Channel channel, Message message){
        log.info("接收到消息：{}",msg);
        return aiService.getAiResponse(msg);
    }
    @Override
    public void confirm(CorrelationData correlationData, boolean flag, String s) {
        if (!flag){
            log.error("消息发送失败：{}",s);
        }
    }

    @Override
    public void returnedMessage(Message message, int i, String s, String s1, String s2) {

    }
}
